# 查找相关的
s = 'index lucy lucky goods'

result = 'r' in s
print(result)  # False

# 查找r
result = s.find('r')   # 返回-1
print(result)
# s.index('r')   # 找不到回报错

# 查找到返回第一个元素出现下标
result = s.find('lucy')
print(result)

# find(str,start,end)
result = s.find('l',7)
print(result)

# 取出cn
#  https://home.firefoxchina.cn/
url = 'https://home.firefoxchina.cn/'
p1 = url.find('.')
p2 = url.rfind('.')
name = url[p1+1:p2]
print(name)

# replace(old, new, max)  max为替换几个
s2 = s.replace(' ','-')
print(s2)
print('\n\n')


# encode(编码)  对字符串进行编码   decode(编码) 对字符串进行解码
s3 = 'wang you jie 王友杰'
s4 = s3.encode('utf-8')  # utf-8针对中文进行编码
print('编码:',s4)
s5 = s4.decode('utf-8')
print('解码:',s5)

# startswith() 以什么开头   endswith()以什么结尾   返回值为布尔类型
filename = 'first.txt'
print(filename.endswith('txt'))   # True
print(filename.startswith('fit'))  # False
print('\n\n')
# 判断上传的是否是py文件并获取文件名(没有后缀名)
path = 'F:\novice_learning_2020\python_study_2020_01_16\String.py'
print(path.rfind('F'))
p1 = path.rfind('\\')
p2 = path.rfind('.')
print(p1,p2)
filename1 = path[p1+1:p2]
endsname = path[p2+1:]
if endsname == 'py':
	print('上传的文件是py文件')
	print('文件名为',filename1)
else:
	print('上传的文件不是py文件')
	
